﻿using QuantumFractals;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Reflection;

namespace QuantumFractals.Tests
{
    [TestClass()]
    public class EvaluatorTest
    {
        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void AddFormulaTest()
        {
            MethodInfo method;

            method = Evaluator.AddFormula("X + 1", "int");
            for (int i = 0; i < 100; i++)
            {
                object[] args = { (double)i};
                Assert.AreEqual(i + 1, method.Invoke(null, args));
            }

            method = Evaluator.AddFormula("X - Y + 1", "int",
                new Dictionary<string, string> { { "Y", "1" } });
            for (int i = 0; i < 100; i++)
            {
                object[] args = { (double)i };
                Assert.AreEqual(i, method.Invoke(null, args));
            }

            method = Evaluator.AddFormula("X - Y + Z + 1", "int",
                new Dictionary<string, string> { { "Y", "1" }, {"Z", "2"} });
            for (int i = 0; i < 100; i++)
            {
                object[] args = { (double)i };
                Assert.AreEqual(i + 2, method.Invoke(null, args));
            }
        }

        [TestMethod()]
        public void CalculateFormulaTest()
        {
            Assert.AreEqual(2 + 2 * 3 + 1, Evaluator.CalculateFormula("2 + 2 * 3 + 1"));
            Assert.AreEqual(2 + 2 * 3, Evaluator.CalculateFormula("2 + 2 * 3"));
            Assert.AreEqual(2 + 2 * 3 - 1, Evaluator.CalculateFormula("2 + 2 * 3 - 1"));
        }

        [TestMethod()]
        public void CalculateFormulaPointsTest()
        {
            Assert.AreEqual(6, new QPoint[] 
                { 
                    new QPoint(0, 0, 1), 
                    new QPoint(1, 0, 0), 
                    new QPoint(0, 1, 0), 
                    new QPoint(-1, 0, 0), 
                    new QPoint(0, -1, 0), 
                    new QPoint(0, 0, -1) 
                }.Length);
            Assert.AreEqual(new QPoint[] { new QPoint(1, 2, 3), new QPoint(4, 5, 6) },
                Evaluator.CalculateFormulaPoints(new string[] { "1,2,3", "4,5,6" }));
        }
    }
}
